package org.eae.eldf.framework.utils;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/******************************************************************************
 * @File name   :      ObjectConvertUtil.java
 *
 * @Author      :      fxm
 *
 * @Date        :      2016-7-6
 *
 * @Copyright Notice: 
 * Copyright (c) 2016 Efast Serv. All  Rights Reserved.
 * This software is published under the terms of the Efast Software
 * License version 1.0, a copy of which has been included with this
 * distribution in the LICENSE.txt file.
 * 
 * 
 * ----------------------------------------------------------------------------
 * Date                   Who         Version        Comments
 * 2016-7-6 下午6:13:40        fxm     1.0            Initial Version
 *****************************************************************************/
public class ObjectConvertUtil {
	public static byte[] objectToByteArray(Object obj) throws Exception {
        byte[] bytes = null;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(obj);
        oos.close();
        bytes = baos.toByteArray();
        baos.close();
        return bytes;
    }
 
    public static Object byteArrayToObject(byte[] buffer) throws Exception {
        Object ob = null;
        ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(
                buffer));
        ob = ois.readObject();
        ois.close();
        return ob;
    }
}
